package cn.mado.org.controller;

import cn.mado.basic.note.SysLog;
import cn.mado.basic.util.AjaxResult;
import cn.mado.basic.util.PageList;
import cn.mado.org.domain.Picture;
import cn.mado.org.query.PictureQuery;
import cn.mado.org.service.PictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/picture")
public class PictureController {

    @Autowired
    private PictureService pictureService;

    /**
     * 查询部门全部
     */
    @SysLog("查询所有写真")
    @GetMapping
    public List<Picture> findAll() {
        return pictureService.findAll();
    }

    /**
     * 添加、修改部门
     */
    @SysLog("添加修改了写真")
    @PostMapping("save")
    public AjaxResult addOrUpdate(@RequestBody Picture picture){
        System.out.println("我来："+picture);
        if (null == picture.getPicId()){
            // 添加
            pictureService.add(picture);
        }else {
            // 修改
            pictureService.update(picture);
        }
        return AjaxResult.me().success();
    }
    /**
     * 删除 delete localhost:8080/picture/1
     */
    @SysLog("删除了一个写真")
    @DeleteMapping("/{picId}")
    public AjaxResult delete(@PathVariable("picId") Long picId){
        System.out.println(picId);
        pictureService.delete(picId);
        return AjaxResult.me().success();
    }


    /**
     * 根据id查询一个
     */
    @SysLog("id查询写真")
    @GetMapping("/{picId}")
    public Picture findById(@PathVariable("picId") Long picId){
        System.out.println(picId);
        return pictureService.findById(picId);
    }

    /**
     *
     * 分页查询
     */
    @PostMapping
    public PageList<Picture> queryByPage(@RequestBody PictureQuery query){
        return pictureService.queryByPage(query);
    }

}
